# -*- coding: utf-8 -*-

from os import path
import utils.jsonrpc as jsonrpc
import logging

ROOT_DIR = path.dirname(__file__)
UNIXSOCKET = path.join(ROOT_DIR,"socketipc")

#server = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 31415)))
#server = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 8086)))

log = logging.getLogger("AlicanteHomebox")

class VideoCommunicator():
    def __init__(self):
        self.server = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportUnixSocket(addr=UNIXSOCKET))
        
        
    def addWatcher(self, channel, ipAddress, port):
        try:
            result = self.server.addwatcher(channel, ipAddress, port)
        except jsonrpc.RPCTransportError, e:
            log.error("No RPC connection with video forwarder: %s" % e)
            return False
        else:
            return result
            
    def removeWatcher(self, channel, ipAddress, port):
            try:
                result = self.server.removewatcher(channel, ipAddress, port)
            except jsonrpc.RPCTransportError, e:
                log.error("No RPC connection with video forwarder: %s" % e)
                return False
            else:
                return result
                
    def deleteWatcher(self, ipAddress, port):
            try:
                result = self.server.deletewatcher(ipAddress, port)
            except jsonrpc.RPCTransportError, e:
                log.error("No RPC connection with video forwarder: %s" % e)
                return False
            else:
                return result
                
                
                
                